/**
 * 
 */
package baidu.des;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;

/**
 * @author Windows Xp
 *
 */
public class DesEncryption extends JFrame {

	private JTextField desTextField;
	private JTextField srcTextField;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (Exception exception) {
			System.exit(ABORT);
		}
		new DesEncryption().setVisible(true);
	}
	public DesEncryption() {
		super();
		
		setTitle("Des加密解密");
		
		setSize(new Dimension(350, 151));
		center();
		setAlwaysOnTop(true);
		getContentPane().setLayout(null);

		final JLabel label = new JLabel();
		label.setText("未处理字符：");
		label.setBounds(10, 28, 88, 18);
		getContentPane().add(label);

		final JLabel label_1 = new JLabel();
		label_1.setText("处理后字符：");
		label_1.setBounds(10, 58, 88, 18);
		getContentPane().add(label_1);

		srcTextField = new JTextField();
		srcTextField.setBounds(104, 26, 229, 22);
		getContentPane().add(srcTextField);

		desTextField = new JTextField();
		desTextField.setBounds(104, 56, 229, 22);
		getContentPane().add(desTextField);

		final JButton button = new JButton();
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent arg0) {
				desTextField.setText(DesUtils.encrypt(srcTextField.getText()));
			}
		});
		button.setText("加密");
		button.setBounds(258, 84, 75, 28);
		getContentPane().add(button);

		final JButton button_1 = new JButton();
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent arg0) {
				desTextField.setText(DesUtils.decrypt(srcTextField.getText()));
			}
		});
		button_1.setText("解密");
		button_1.setBounds(177, 84, 75, 28);
		getContentPane().add(button_1);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	/**
	 * 位置居中
	 */
	private void center() {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((int)(screenSize.getWidth()-getSize().getWidth())/2, (int)(screenSize.getHeight()-getSize().getHeight())/2);
	}
}
